package projectManagementServer;

import javax.swing.*;

import java.awt.*;
import java.util.ArrayList;

import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;

public class OnlineUserPanel extends JPanel {
	
	DefaultListModel<String> onlineUserListModel;
	JList<String> onlineUserList;
	ArrayList<String> onlineUser;
	
	public OnlineUserPanel(ArrayList<String> onlineUser) {
		setPreferredSize(new Dimension(354, 378));
		setLayout(null);
		
		this.onlineUser = onlineUser;
		
		JPanel mainPanel = new JPanel();
		mainPanel.setBorder(new TitledBorder(null, "Online Users", TitledBorder.CENTER, TitledBorder.TOP, null, null));
		mainPanel.setBounds(10, 11, 334, 356);
		mainPanel.setLayout(new BorderLayout(0, 0));
		add(mainPanel);
		
		onlineUserListModel = new DefaultListModel<>();
		for(String x : onlineUser){
			onlineUserListModel.addElement(x);
		}
		
		onlineUserList = new JList<>();
		onlineUserList.setFont(new Font("Tempus Sans ITC", Font.PLAIN, 15));
		onlineUserList.setModel(onlineUserListModel);
		onlineUserList.setSelectedIndex(-1);
		onlineUserList.setVisibleRowCount(0);
		onlineUserList.setValueIsAdjusting(true);
		onlineUserList.setLocation(0,0);
		onlineUserList.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
		onlineUserList.putClientProperty( "Quaqua.List.style", "striped");
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setViewportView(onlineUserList);
		scrollPane.setBorder(new EmptyBorder(0,0,0,0));
		mainPanel.add(scrollPane, BorderLayout.CENTER);
		
		JFrame f = new JFrame();
		f.setResizable(false);
		f.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
		f.add(this);
		f.setVisible(true);
		f.pack();
		f.setLocationRelativeTo(null);
		
		
	}

}
